--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_tatara_kogasa = General:new(extension, "hy_tatara_kogasa", "jin_k", 4, 4, General.Female)

    local rain_night = fk.CreateSkill {
        name = "rain_night",
    }

    ---@param room Room
    ---@param target ServerPlayer
    ---@param random boolean
    local function DoRainNight(room, target, random)
        if target.dead then
            return
        end
        local choice1 = "rain_night_choice1"
        local choice2 = "rain_night_choice2"
        local choice3 = "rain_night_choice3"
        local choices = { choice1, choice2, choice3 }
        local valid = table.clone(choices)
        if target:isKongcheng() then
            table.removeOne(valid, choice1)
        end
        local result
        if random then
            result = table.random(valid)
        else
            result = room:askToChoice(target, {
                choices = valid,
                all_choices = choices,
                skill_name = rain_night.name,
                prompt = "rain_night_prompt"
            })
        end
        if result == choice1 then
            room:throwCard(table.random(target:getCardIds("h")), rain_night.name, target, target)
        elseif result == choice2 then
            room:loseHp(target, 1, rain_night.name)
        elseif result == choice3 then
            local judge = {
                who = target,
                pattern = ".|.|spade",
                reason = rain_night.name
            }
            room:judge(judge)
            if judge.card and judge.card.suit == Card.Spade then
                room:damage({
                    to = target,
                    damage = 3,
                    damageType = fk.ThunderDamage,
                    skillName = rain_night.name
                })
            end
        end
    end

    rain_night:addEffect(fk.RoundStart, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(rain_night.name)
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local judge = {
                who = player,
                pattern = ".|1,11",
                reason = rain_night.name
            }
            room:judge(judge)
            if judge.card and (judge.card.number == 1 or judge.card.number == 11) then
                room:setPlayerMark(player, "@@rain_night-round", 1)
            end
        end
    })
    rain_night:addEffect("atkrange", {
        fixed_func = function(self, player)
            if player:hasSkill(rain_night.name) and (player:getMark("@@rain_night-round") ~= 0 or player:getMark("@@rain_night-turn") ~= 0) then
                return 999
            end
        end
    })
    rain_night:addEffect(fk.CardUseFinished, {
        is_delay_effect = true,
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(rain_night.name) and (player:getMark("@@rain_night-round") ~= 0 or player:getMark("@@rain_night-turn") ~= 0) and target ~= player and data.card.type ~= Card
                .TypeBasic
        end,
        on_use = function(self, event, target, player, data)
            DoRainNight(player.room, target, false)
        end
    })

    local sudden_threat = fk.CreateSkill {
        name = "sudden_threat",
    }
    sudden_threat:addEffect(fk.CardUseFinished, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(sudden_threat.name) and target == player and data.card.is_damage_card and table.any(data:getAllTargets(), function(t)
                return player:inMyAttackRange(t)
            end)
        end,
        on_cost = function(self, event, target, player, data)
            local room = player.room
            local targets = table.filter(data:getAllTargets(), function(t)
                return player:inMyAttackRange(t)
            end)
            if #targets == 1 then
                if room:askToSkillInvoke(player, {
                        skill_name = sudden_threat.name,
                        prompt = "sudden_threat_prompt1::" .. targets[1].id
                    }) then
                    event:setCostData(self, targets[1])
                    return true
                end
            else
                local result = room:askToChoosePlayers(player, {
                    targets = targets,
                    min_num = 1,
                    max_num = 1,
                    skill_name = sudden_threat.name,
                    prompt = "sudden_threat_prompt2"
                })
                if #result == 1 then
                    event:setCostData(self, result[1])
                    return true
                end
            end
        end,
        on_use = function(self, event, target, player, data)
            DoRainNight(player.room, event:getCostData(self), true)
        end
    })

    local call_flood = fk.CreateSkill {
        name = "call_flood",
    }
    call_flood:addEffect(fk.Damaged, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(call_flood.name) and target == player
        end,
        on_cost = function(self, event, target, player, data)
            local room = player.room
            if player:getMark("@@rain_night-round") == 0 and player:getMark("@@rain_night-turn") == 0 then
                return room:askToSkillInvoke(player, {
                    skill_name = call_flood.name,
                    prompt = "call_flood_prompt1"
                })
            elseif data.from then
                return room:askToSkillInvoke(player, {
                    skill_name = call_flood.name,
                    prompt = "call_flood_prompt2::" .. data.from.id
                })
            end
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            if player:getMark("@@rain_night-round") == 0 and player:getMark("@@rain_night-turn") == 0 then
                room:drawCards(player, 1, call_flood.name)
                room:setPlayerMark(player, "@@rain_night-turn", 1)
            elseif data.from then
                DoRainNight(room, data.from, true)
            end
        end
    })

    extension:loadSkillSkels { rain_night, sudden_threat, call_flood }
    hy_tatara_kogasa:addSkills { "rain_night", "sudden_threat", "call_flood" }

    Fk:loadTranslationTable {
        ["hy_tatara_kogasa"] = "多多良小伞",
        ["#hy_tatara_kogasa"] = "骤雨惊奇",
        ["illustrator:hy_tatara_kogasa"] = "Boss",
        ["designer:hy_tatara_kogasa"] = "黑曜人形",
        ["cv:hy_tatara_kogasa"] = "",

        ["rain_night"] = "雨夜",
        [":rain_night"] = "每轮开始时，你进行判定：若点数为A或J，本轮你的攻击范围无限且其他角色使用非基本牌结算结束后须选择一项：1.随机弃置一张手牌；2.失去1点体力；3.进行一次判定，若为♠则受到3点雷电伤害。",
        ["@@rain_night-round"] = "雨夜",
        ["@@rain_night-turn"] = "雨夜",
        ["rain_night_prompt"] = "雨夜：你须选择一项",
        ["rain_night_choice1"] = "随机弃置一张手牌",
        ["rain_night_choice2"] = "失去1点体力",
        ["rain_night_choice3"] = "判定，若为♠则受到3点雷电伤害",

        ["sudden_threat"] = "骤袭",
        [":sudden_threat"] = "你对攻击范围内的角色使用伤害类牌结算结束后，你可以令其中一名角色随机执行“雨夜”中的一项。",
        ["sudden_threat_prompt1"] = "骤袭：你可以令%dest随机执行“雨夜”中的一项",
        ["sudden_threat_prompt2"] = "骤袭：你可以令一名角色随机执行“雨夜”中的一项",

        ["call_flood"] = "唤汛",
        [":call_flood"] = "在你受到伤害后，若“雨夜”未生效：你可以摸一张牌并令“雨夜”本回合视为生效；否则你可以令伤害来源随机执行“雨夜”中的一项。",
        ["call_flood_prompt1"] = "唤汛：你可以摸一张牌并令“雨夜”本回合视为生效",
        ["call_flood_prompt2"] = "唤汛：你可以令%dest随机执行“雨夜”中的一项",
    }
end
